import java.util.ArrayList;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...

        int n = scan.nextInt();
        scan.nextLine();



        func(n,scan);

        scan.close();




    }


    private static void func(int n,Scanner scan) {





        int[] syn = new int[n];


        while (scan.hasNextLine()) {
            String s = scan.nextLine();
            String[] ss = s.split(" ");



            if (ss[0].equals("add")) {

                syn[0]++;


            } else if (ss[0].equals("query")) {
                int count = 0x3f3f3f3f;

                for (int i = 1; i < n; i++) {
                    count = Math.min(count, syn[i]);
                }

                System.out.println(count);

            } else if (ss[0].equals("sync")) {
                int followerId = Integer.parseInt(ss[1]);
                if (followerId >= 1 && followerId < n) {
                    if (syn[followerId] < syn[0]) {
                        syn[followerId]++;
                    }


                }


            }




        }
    }
}